package com.back.controller;

import com.back.common.utils.Result;
import com.back.common.utils.SecurityUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 公共功能控制器
 * 提供所有角色都可以访问的功能
 */
@RestController
@RequestMapping("/common")
@Api(tags = "公共功能接口")
@Slf4j
public class CommonController {

    /**
     * 获取当前用户信息
     */
    @ApiOperation(value = "获取当前用户信息")
    @GetMapping("/userinfo")
    public Result getUserInfo() {
        String username = SecurityUtil.getCurrentUsername();
        boolean isAdmin = SecurityUtil.isAdmin();
        boolean isEmployer = SecurityUtil.isEmployer();
        boolean isJobSeeker = SecurityUtil.isJobSeeker();
        
        return Result.ok().message("获取用户信息成功")
                .data("username", username)
                .data("isAdmin", isAdmin)
                .data("isEmployer", isEmployer)
                .data("isJobSeeker", isJobSeeker);
    }
    
    /**
     * 搜索职位
     */
    @ApiOperation(value = "搜索职位")
    @GetMapping("/job/search")
    public Result searchJobs(@RequestParam(required = false) String keyword,
                             @RequestParam(required = false) String location,
                             @RequestParam(required = false) String category,
                             @RequestParam(required = false, defaultValue = "1") Integer page,
                             @RequestParam(required = false, defaultValue = "10") Integer size) {
        log.info("搜索职位, 关键词: {}, 地点: {}, 类别: {}, 页码: {}, 每页大小: {}", 
                keyword, location, category, page, size);
        return Result.ok().message("职位搜索成功");
    }
    
    /**
     * 获取职位详情
     */
    @ApiOperation(value = "获取职位详情")
    @GetMapping("/job/{id}")
    public Result getJobDetail(@PathVariable Long id) {
        log.info("获取职位详情, ID: {}", id);
        return Result.ok().message("获取职位详情成功");
    }
    
    /**
     * 获取企业详情
     */
    @ApiOperation(value = "获取企业详情")
    @GetMapping("/company/{id}")
    public Result getCompanyDetail(@PathVariable Long id) {
        log.info("获取企业详情, ID: {}", id);
        return Result.ok().message("获取企业详情成功");
    }
    
    /**
     * 获取职位类别列表
     */
    @ApiOperation(value = "获取职位类别")
    @GetMapping("/job/categories")
    public Result getJobCategories() {
        return Result.ok().message("获取职位类别成功");
    }
} 